// -----------------------------------------------------------------------
//  <copyright file="FunctionAuthResult.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2023 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2023-12-21 14:33</last-date>
// -----------------------------------------------------------------------

namespace DaprPlus.Authorization;

/// <summary>
/// 功能权限检查结果
/// </summary>
public class AuthorizationResult : OsharpResult<AuthorizationStatus>
{
    public AuthorizationResult(AuthorizationStatus status) : this(status, null)
    { }

    public AuthorizationResult(AuthorizationStatus status, string? message) : this(status, message, null)
    { }

    public AuthorizationResult(AuthorizationStatus status, string? message, object? data)
        : base(status, message, data)
    { }

    /// <summary>获取或设置 返回消息</summary>
    public override string Message
    {
        get => _message ?? ResultType.ToDescription();
        set => _message = value;
    }

    /// <summary>获取 是否成功</summary>
    public bool IsOk => ResultType == AuthorizationStatus.Ok;

    /// <summary>获取 是否未授权</summary>
    public bool IsUnauthorized => ResultType == AuthorizationStatus.Unauthorized;

    /// <summary>获取 是否禁止访问</summary>
    public bool IsForbidden => ResultType == AuthorizationStatus.Forbidden;

    /// <summary>获取 是否未找到</summary>
    public bool IsNoFound => ResultType == AuthorizationStatus.NotFound;

    /// <summary>获取 是否发生错误</summary>
    public bool IsError => ResultType == AuthorizationStatus.Error;

    /// <summary>
    /// 获取 检查成功的结果
    /// </summary>
    public static AuthorizationResult Ok { get; } = new(AuthorizationStatus.Ok);
}
